package com.ruoyi.web.controller.finance;

import java.io.IOException;
import java.util.List;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.file.FileUploadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.finance.domain.FmsRecord;
import com.ruoyi.finance.service.IFmsRecordService;
import org.springframework.web.multipart.MultipartFile;

/**
 * 财务记录 操作处理
 *
 * @author 夜雨
 */
@RestController
@RequestMapping("/finance/record")
public class FmsRecordController extends BaseController
{
    @Autowired
    private IFmsRecordService recordService;

    /**
     * 获取财务记录列表
     */
    @PreAuthorize("@ss.hasPermi('finance:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(FmsRecord record)
    {
        startPage();
        List<FmsRecord> list = recordService.selectRecordList(record);
        return getDataTable(list);
    }

    /**
     * 根据财务记录编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance:record:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable Long recordId)
    {
        return success(recordService.selectRecordById(recordId));
    }

    /**
     * 新增财务记录
     */
    @PreAuthorize("@ss.hasPermi('finance:record:add')")
    @Log(title = "财务记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody FmsRecord record)
    {
        record.setCreateBy(getUsername());
        return toAjax(recordService.insertRecord(record));
    }

    /**
     * 修改财务记录
     */
    @PreAuthorize("@ss.hasPermi('finance:record:edit')")
    @Log(title = "财务记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody FmsRecord record)
    {
        record.setUpdateBy(getUsername());
        return toAjax(recordService.updateRecord(record));
    }

    /**
     * 删除财务记录
     */
    @PreAuthorize("@ss.hasPermi('finance:record:remove')")
    @Log(title = "财务记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(recordService.deleteRecordByIds(recordIds));
    }

}
